package com.xd.springboot.controller;

import com.xd.springboot.entity.Blogger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/thymeleaf")
public class ThemyLeafController {

     @RequestMapping("/index")
    public  String index()
    {
        return "index";
    }

    @RequestMapping("/test404")
    public  String test404()
    {
        return "index";
    }

    @RequestMapping("/test500")
    public  String test500()
    {
        int i = 1 / 0;
        return "index";
    }

    @GetMapping("/getBlogger")
    public  String getBlogger(Model model){
        Blogger blogger=new Blogger(1L,"测试","11111");
        model.addAttribute("blogger",blogger);
        return "blogger";
    }

    @GetMapping("/getlist")
    public  String getList(Model model)
    {
        Blogger blogger1=new Blogger(1L,"测试","11111");
        Blogger blogger2=new Blogger(2L,"测试222","111112222");
        List<Blogger> list=new ArrayList<>();
        list.add(blogger1);
        list.add(blogger2);
        model.addAttribute("list",list);
        return "list";
    }

}
